package com.grape.action.system;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.grape.action.common.BaseAction;
import com.grape.domain.system.Permission;
import com.grape.service.system.PermissionService;

@Namespace("/")
@Scope("prototype")
@Controller
@ParentPackage("json-default")
public class PermissionAction extends BaseAction<Permission>{
	private static final long serialVersionUID = 1L;
	@Autowired
	private PermissionService ps;
	
	@Action(value="permission_list",results=@Result(name="success",type="json"))
	public String list() {
		List<Permission> list = ps.findAll();
		ServletActionContext.getContext().getValueStack().push(list);
		return SUCCESS;
	}
	
	@Action(value="permission_save",results=@Result(name="success",type="json"))
	public String save() {
		ps.save(model);
		
		Map<String,Object> mp = new HashMap<>();
		mp.put("msg", model.getName()+"权限保存成功");
		ServletActionContext.getContext().getValueStack().push(mp);
		return SUCCESS;
	}
}
